<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改电池信息页面</title>
    <script src="js/jquery-3.6.0.js"></script>
</head>
<body>
    <h1 align="center">修改电池信息页面</h1>
    <form method="post" action="UpdateServlet?id=${sessionScope.powerBattery.id}">
        <table border="1px" align="center">
            <tr>
                <td>车辆类型</td>
                <td><input type="text" name="carName" value="${sessionScope.powerBattery.carName}" id="carName"></td>
            </tr>
            <tr>
                <td>所属城市</td>
                <td><input type="text" name="cityName" id="cityName" value="${sessionScope.powerBattery.cityName}"></td>
            </tr>
            <tr>
                <td>使用单位</td>
                <td><input type="text" name="userName" id="userName" value="${sessionScope.powerBattery.userName}"></td>
            </tr>
            <tr>
                <td>压差报警值</td>
                <td><input type="text" name="pressureValue" id="pressureValue" value="${sessionScope.powerBattery.pressureValue}"></td>
            </tr>
            <tr>
                <td>报警时间</td>
                <td><input type="text" name="time" id="time" value="${sessionScope.powerBattery.time}"></td>
            </tr>
            <tr>
                <td>操作</td>
                <td><input type="submit" value="修改"></td>
            </tr>
        </table>
    </form>
<script>
    $(function (){
        $("form").submit(function (){
            if ($("#carName").val().trim()=="" || $("#cityName").val().trim()=="" || $("#userName").val().trim()==""){
                alert("请填写完整的信息!")
                return false;
            }
            if (isNaN($("#pressureValue").val())){
                alert('压差报警值必须是数值类型')
                return false;
            }
            let reDate = /^\d{4}-\d{1,2}-\d{1,2}$/;
            let time = $("#time").val().trim();
            if (!reDate.test(time)){
                alert('时间格式不合法，正确格式是yyyy-MM-dd')
                return false;
            }
        })
    })
</script>
</body>
</html>
